package com.example.testapp.activity.activity;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
import android.view.inputmethod.InputMethodManager;

import com.example.testapp.activity.http.RetryNetwork;
import com.example.testapp.activity.listener.PwdErrorListener;
import com.example.testapp.activity.util.UserController;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * Created by l on 2016/7/11.
 */
public abstract class BaseActivity extends FragmentActivity implements RetryNetwork, PwdErrorListener {

    protected boolean isAvtive = false;
    protected Context mContext;
    protected boolean isPwdError = false;

    protected UserController mUserController;

    private InputMethodManager imm;

    private ProgressDialog progress;
    /**
     * 用于判断APP是否是正常启动,还是奔溃后自动重启的
     */
    protected static boolean isNormalStart = false;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        mContext = this;
        isAvtive = true;
        imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

        mUserController = UserController.getInstance(mContext.getApplicationContext());
    }

    @Override
    protected void onResume() {
        super.onResume();
        obtainInfo();
        isAvtive = true;

        if(!isNormalStart) {

        }
    }

    /**
     * 接收数据
     */
    protected abstract void obtainInfo();


    @Override
    protected void onPause() {
        super.onPause();
        isAvtive = false;

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        isAvtive = false;

    }

    @Override
    public void pwdError() {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                isPwdError = true;
            }
        });
    }

    /**
     * UI线程执行一个任务
     *
     * @param run
     */
    protected void runOnUi(Runnable run) {
        runOnUiThread(run);
    }

    @Override
    public void retry() {

    }

    @Override
    public void netError() {

    }

    public boolean getAvtive() {
        return isAvtive;
    }


}
